import { Service, RequestParams } from 'vue-element-simple'
import { getToken, getSaaSId } from '../utils/auth'

Service.getToken = function() {
  return getToken();
}

/**
 * 图片上传
 * @param params
 * @returns {Promise.<*>}
 */
Service.adminImageUpload = async function(params = {}) {
  const request = new RequestParams();
  //  文件流
  request.put('file', params['file']);
  // SaasId
  request.put('mallId', getSaaSId());
  return await this.getService(`/admin/image/upload`, request);
}

/**
 * 获取历史上传图片列表
 * @returns {Promise.<*>}
 */
Service.adminImageGetHistoryList = async function(params) {
  const request = new RequestParams();
  // 页数
  request.put('page', params['page'], 1);
  // 每页条数
  request.put('pageSize', params['pageSize'], 20);
  // SaasId
  request.put('mallId', getSaaSId());
  return await this.getService(`/admin/image/getHistoryList`, request);
}

/**
 * 删除历史上传图片
 * @returns {Promise.<*>}
 */
Service.adminImageDelHistory = async function(params) {
  const request = new RequestParams();
  //  图片ID(多个用,分隔)
  request.put('ids', params['ids']).checkEmpty('图片ID');
  // SaasId
  request.put('mallId', getSaaSId());
  return await this.getService(`/admin/image/delHistory`, request);
}
